import 'package:flutter/material.dart';
import 'package:untitled/utils/scopoed_model_helper.dart';
import 'package:untitled/widgets/common_image.dart';

import '../../../scoped_model/AuthModel.dart';

class Header extends StatelessWidget {

  const Header({Key key}) : super(key: key);

  Widget _notLoginBuilder(BuildContext context){
    return Container(
      padding: EdgeInsets.only(left: 15.0),
      decoration: BoxDecoration(
          color: Colors.green
      ),
      height: 95.0,
      child: Row(
        children: [
          Container(
            height: 65.0,
            width: 65.0,

            child: CircleAvatar(backgroundImage: AssetImage('static/images/home_profile_user.png'),),
          ),
          SizedBox(width: 10,),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Row(
                children: [
                  GestureDetector(
                    child: Text('登录',style: TextStyle(
                        color: Colors.white,
                        fontSize: 18.0
                    ),),
                    onTap: (){
                      Navigator.of(context).pushNamed('login');
                    },
                  ),
                  Text('/',style: TextStyle(
                      color: Colors.white,
                      fontSize: 18.0
                  )),
                  GestureDetector(
                    child: Text('注册',style: TextStyle(
                        color: Colors.white,
                        fontSize: 18.0
                    )),
                    onTap: (){
                      Navigator.of(context).pushNamed('register');
                    },
                  ),
                ],
              ),


              Text('登录后可体验更多',style:TextStyle(
                  color: Colors.white,
                  fontSize: 14.0
              ),)
            ],
          )
        ],
      ),
    );
  }

  Widget _loginBuilder(BuildContext context){
    String username = "张三";
    String faceUrl = "https://c-ssl.duitang.com/uploads/blog/202101/23/20210123215342_3bbf3.thumb.1000_0.jpeg";
    return Container(
      padding: EdgeInsets.only(left: 15.0),
      decoration: BoxDecoration(
          color: Colors.green
      ),
      height: 95.0,
      child: Row(
        children: [
          Container(
            height: 65.0,
            width: 65.0,

            child: CircleAvatar(backgroundImage: NetworkImage(faceUrl),),
          ),
          SizedBox(width: 10,),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(username,style: TextStyle(
                  color: Colors.white,
                  fontSize: 18.0
              )),


              Text('查看编辑个人资料',style:TextStyle(
                  color: Colors.white,
                  fontSize: 14.0
              ),)
            ],
          )
        ],
      ),
    );
  }
  @override
  Widget build(BuildContext context) {
    var login = ScopedModelHelper.getModel<AuthModel>(context).isLogin;
    return login? _loginBuilder(context):_notLoginBuilder(context);
  }
}
